<%@page import="Board.BoardVo"%>
<%@page import="java.util.ArrayList"%>
<%@page import="Board.BoardMyba"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script
	src="${pageContext.request.contextPath }/se2/js/HuskyEZCreator.js"
	type="text/javascript" charset="utf-8"></script>
<!-- 이미지 업로드 관련 js파일 -->
<script
	src="${pageContext.request.contextPath }/se2/photo_uploader/plugin/hp_SE2M_AttachQuickPhoto.js"
	type="text/javascript" charset="utf-8"></script>
<title>게시판 수정</title>
<script>
	
	function modi(frm) {
		var sHTML = oEditors.getById["textAreaContent"].getIR();
		frm.bo_content.value = sHTML;
		
		var m = document.getElementById("text_title");
		if (m.value.trim() == "") {
			alert("제목을 입력해주세요.");
			m.focus();
			return false;
		}
		if (sHTML == "" || sHTML == "<br>") {
			alert("내용을 입력해주세요.");
			return false;
		}

		var r = confirm("등록하시겠습니까?");
		if (r) {
			frm.action = 'index.jsp?inc_content=./board/board_modify_result.jsp';
			frm.submit();
		} else {

		}
		
		
		frm.action = 'index.jsp?inc_content=./board/board_modify_result.jsp&bo_no='
				+ bo_no;
		frm.submit();
	}

	function mod(serial) {
		/* var sHTML = oEditors.getById["textAreaContent"].getIR();
		frm.bo_content.value = sHTML; */

		
	}
	function Del(f, serial) {
		var v = confirm("정말 삭제하시겠습니까?");
		if (v) {
			location.href = 'index.jsp?inc_content=./board/board_modify.jsp&bo_no='
					+ serial + "&fileDelete=" + f;
		} else {

		}
	}
	function init(){
		var resetkey = document.getElementsByTagName("body").item(0);
		resetkey.onkeydown = function(ev){
			var key = ev.charCode || ev.keyCode || key.whitch;
			if(key == 116){
				var s = confirm("창을 갱신하시겠습니까? 작업하던 데이터는 다시 돌아오지 않습니다.");
				if(s){
					
				}else{
					return false;
				}
			}
		};	
	}
</script>
<style>
#main_div {
	width: 900px;
	margin: 0 auto;
	margin-top: 20px;
}
/*Board부분*/
#select_box {
	width: 150px;
}

#board_title,#board_title_text {
	display: inline-block;
}

/*#board_title {
	width: 150px;
	border-right: 1px dotted #dddddd;
	text-align: center;
	
}*/
#board_title_text {
	width: 743px;
}

#board_con_title,#board_con_text,#board_master_radio {
	display: inline-block;
	margin-top: 5px;
}

#board_con_title {
	width: 150px;
	text-align: center;
	background-color: #c0ecff;
}

#board_master_radio {
	font-size: 10pt;
}

/*#board_con_text {
	width: 590px;
	height: 300px;
	border-left: 1px dotted #dddddd;
}*/

/*제목창 조절*/
#text_title {
	min-width: 500px;
	max-width: 500px;
}
/*파일창 크기 조절*/
#file_box {
	border: 1px solid #dddddd;
	width: 898px;
}

/*여기에 SmartEditer을 적용시킴*/
#board_con_text {
	width: 900px;
}

/*SmartEditer 조절*/
#textAreaContent {
	min-width: 892px;
	max-width: 892px;
	min-height: 500px;
	max-height: 500px
}

#file_title,#file_text {
	display: inline-block;
	margin-top: 5px;
}

#file_text {
	width: 743px;
}

#file_name {
	font-size: 9pt;
	border: 1px solid #F1F1F1;
	width: 898px;
	height: 25px;
}

/*버튼 담당*/
#button {
	margin-top: 10px;
	width: 900px;
	height: 40px;
	border: 1px dotted #dddddd;
	/*border-bottom :1px dotted #dddddd;*/
	background-color: #eeeeee;
	margin-bottom: 30px;
}

#submit,#btnlist,#delete {
	margin-top: 8px;
	margin-right: 4px;
}

#submit {
	width: 50px;
	height: 25px;
	cursor: pointer;
	background-color: #7f7f7f;
	color: white;
	border: 1px solid #7f7f7f;
	font-weight: bold;
}

#btnlist {
	width: 50px;
	height: 25px;
	cursor: pointer;
	background-color: #7f7f7f;
	color: white;
	border: 1px solid #7f7f7f;
	font-weight: bold;
}

#button_del {
	border: 1px solid #7f7f7f;
	background-color: #7f7f7f;
	font-weight: bold;
	color: white;
	cursor: pointer;
}

/*배너쪽 담당*/
#banner_box {
	width: 900px;
	height: 50px;
	background-image: url(./board/images/write.jpg);
	margin-bottom: 10px;
}
</style>

</head>
<body>
	<jsp:useBean id="boardVo" class="Board.BoardVo" />
	<jsp:setProperty property="*" name="boardVo" />
	<%
		String mid = (String) session.getAttribute("Mid");
		BoardMyba board = new BoardMyba();
		String fileDelFlag = "";
		if (request.getParameter("fileDelete") != null) {
			fileDelFlag = request.getParameter("fileDelete");
		}
		boardVo.setBo_no(request.getParameter("bo_no"));

		board.setVo(boardVo);
		BoardVo vo = board.view();
		String pa = vo.getBo_part();
		String box = vo.getBo_checked();
	%>
	<script type="text/javascript">
		window.onload = function() {
			var con = document.getElementById("select_box");
			
				<%if (mid.equals("1408M001")) {%>
				<%if (pa.equals("공지사항")) {%>
					con.options[0].selected = true;
				<%}else if(!pa.equals("공지사항")){%>
					con.options[0].selected = true;
				<%}%>
			<%} else {%>
			<%if (pa.equals("인사팀")) {%>
				con.options[0].selected = true;
				<%} else if (pa.equals("개발팀")) {%>
					con.options[1].selected = true;
				<%} else if (pa.equals("총무팀")) {%>
					con.options[2].selected = true;
				<%} else if (pa.equals("홍보팀")) {%>
					con.options[3].selected = true;
				<%} else if (pa.equals("건의사항")) {%>
					con.options[4].selected = true;
				<%}%>
			
			<%}%>
			var chk = document.getElementById("board_radio");
			chk.options[0].selected = true;
		};
	</script>
	<form name='frm' method='post' enctype='multipart/form-data' action=''
		onsubmit="return modi(this)">
		<input type="hidden" name='bo_no' value = '<%=vo.getBo_no()%>'> <input type='hidden'
			name='bo_file' value="<%=vo.getBo_file()%>">
		<%-- <input type = 'hidden' name = 'serial' value = '<%=vo.getBo_no() %>'> --%>
		<input type='hidden' name='fileDelete' value="<%=fileDelFlag%>">
		<!-- onsubmit="return submit(this)" -->
		<div id='main_div'>
			<div id='banner_box'></div>
			<div id='board_title_div'>
				<div id='board_title'>
					<%
						if (mid.equals("1408M001")) {
					%>
					<select id='select_box' name='bo_part'>
						<option value="공지사항">공지사항</option>
					</select>
					<%
						} else {
					%>
					<select id='select_box' name='bo_part'>
						<option value="인사팀">인사팀</option>
						<option value="개발팀">개발팀</option>
						<option value="총무팀">총무팀</option>
						<option value="홍보팀">홍보팀</option>
						<option value="건의사항">건의사항</option>
					</select>
					<%
						}
					%>

				</div>
				<div id='board_title_text'>
					<input type='text' name='bo_title' id='text_title'
						value='<%=vo.getBo_title()%>'>

					<div id='board_master_radio'>
						<%
							if (mid.equals("1408M001")) {
						%>
						<%
							if (vo.getBo_checked().equals("Y")) {
						%>
						<input type="checkbox" id='board_radio' name='bo_checked'
							value="Y" checked="checked">중요공지로 올림(관리자모드)
						<%
							} else {
						%>
						<input type="checkbox" id='board_radio' name='bo_checked'
							value="Y">중요공지로 올림(관리자모드)
						<%
							}
						%>
						<%
							} else {
						%>

						<%
							}
						%>
					</div>
				</div>
			</div>
			<div id='file_div'>
				<div id=file_text>
					<%
						if (vo.getBo_file() == null || fileDelFlag.equals("fileDelete")) {
					%>
					<input type="file" name='new_bo_file' id='file_box'>
					<%
						} else {
					%>
					<div id='file_name'>

						현재 파일 :
						<%=vo.getBo_file()%>
						<input type='button' value='삭제'
							onclick="Del('fileDelete', '<%=vo.getBo_no()%>')" id='button_del'>

					</div>
					<%
						}
					%>

				</div>
			</div>
			<div id='board_content'>
				<div id='board_con_text'>
					<textarea name='bo_content' id='textAreaContent'><%=vo.getBo_content()%></textarea>
				</div>
			</div>
			<div id='button' align="right">
				<input type='submit' value='수정' id='submit'> <input type='button'
					value='취소' id='btnlist' onclick="history.back()">
			</div>
		</div>
	</form>
	<script>init();</script>
	<script type="text/javascript">
		//스마트 에디터 붙이는 부분
		var oEditors = [];
		nhn.husky.EZCreator
				.createInIFrame({
					oAppRef : oEditors,
					elPlaceHolder : "textAreaContent",
					sSkinURI : "${pageContext.request.contextPath }/se2/SmartEditor2Skin.html",
					fCreator : "createSEditor2",
					
					htParams : {
					
					fOnBeforeUnload : function(){
							
					}
				}
			});
		// textArea에 이미지 첨부
		function pasteHTML(filepath) {
			var sHTML = '<img src="${pageContext.request.contextPath }/se2/upload/'+filepath+'">';
			oEditors.getById["textAreaContent"].exec("PASTE_HTML", [ sHTML ]);
		};
	</script>
</body>
</html>